-- 17.lua
-- Created by zouyb Jun/26/2015
-- 土元素BUFF光效

local function isElement(baseClassId)
    local elements = {14, 15, 16, 17};
	return table.indexOf(elements, baseClassId) ~= -1;
end

return {
    onAppear = function(monster)    
		-- 出现新元素时，场上全体元素（包含新出的），播放“属性增益”光效
        do return; end

		-- 当前关卡
		local uiCurLevel = UIDungeonMgr.getCurLevel();
		
	    -- 当前怪物的基类ID
		local baseClassId = monster:query("base_class_id");

		-- 获取其他所有土元素
        local openMonsterGrids = UIDungeonMgr:getCurLevel():getOpenMonsterGrids();
        local count = 0;
        for i = 1, #openMonsterGrids do
            local monsterGrid = openMonsterGrids[i];
            if isElement(monsterGrid.gridData.monster:query("base_class_id")) then
                count = count + 1;
            end
        end
            
        if count >= 2 then
            for i = 1, #openMonsterGrids do
    			local monsterGrid = openMonsterGrids[i];
    			if isElement(monsterGrid.gridData.monster:query("base_class_id")) then
    				playAddBuffEffect(monsterGrid, BUFF_TYPE_ATTACK);
    			end
    		end
    	end	
    end,

    onDie = function(monster)    
		-- 每死亡一只土元素，其他元素播放“属性减益”光效
        do return; end

		-- 当前关卡
		local uiCurLevel = UIDungeonMgr.getCurLevel();
		
		-- 当前怪物的基类ID
		local baseClassId = monster:query("base_class_id");

		-- 获取其他所有土元素
        local openMonsterGrids = UIDungeonMgr:getCurLevel():getOpenMonsterGrids();
        for i = 1, #openMonsterGrids do
			local monsterGrid = openMonsterGrids[i];
            if monsterGrid.gridData.monster ~= monster and isElement(monsterGrid.gridData.monster:query("base_class_id")) then
				playAddDeBuffEffect(monsterGrid, DEBUFF_TYPE_ATTACK);
			end
		end
    end,
};